<!--
 * @Author: lixb
 * @Date: 2020-08-19 10:29:30
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2020-09-24 11:14:49
 * @Descripttion: 活动报名
-->
<template>
  <div v-show="list.length > 0">
    <el-card class="box-card activity-wrap">
      <div slot="header" class="clearfix" style="cursor: pointer;" @click="goVotePage()">
        <span class="modul-title">
          <img
            src="@/assets/img/活动报名.png"
            style="height: 25px;width: 25px;margin-right: 10px;"
          />
          <span>活动报名</span>
        </span>
      </div>
      <div class="text item">
        <el-carousel indicator-position="outside" height="100px" arrow="never">
          <el-carousel-item v-for="item in list" :key="item.id">
            <div style="cursor: pointer;" @click="goVotePage(item)">
              <div class="activity-status">进行中</div>
              <span>【{{ item.activityType == 1 ? '报名' : '投票' }}】{{ item.entryTitle }}</span>
              <p class="activity-text">
                已报名/总人数：{{ item.joinNumber }}/{{ item.shareCount }}人
              </p>
              <p class="activity-text">截止时间：{{ item.entryEndTime }}</p>
            </div>
          </el-carousel-item>
        </el-carousel>
      </div>
    </el-card>
  </div>
</template>

<script>
  import { getVotePage } from '@/api/home';
  import { hasMenu } from '@/plugins/hasMenu';
  export default {
    data() {
      return {
        list: [],
      };
    },
    activated() {
      this.getActivityList();
    },
    methods: {
      getActivityList() {
        getVotePage().then(res => {
          this.list = res.data.length > 3 ? res.data.slice(0, 3) : res.data || [];
        });
      },
      goVotePage(item) {
        if (hasMenu('WALFARE-QTXT-NHXT')) {
          if (item) {
            this.$router.push({
              path: '/voteSignup',
              query: {
                id: item.id,
                flag: 'from_home',
                activityType: item.activityType,
                curTime: Math.round(new Date() / 1000),
              },
            });
          } else {
            this.$router.push('/voteSignup');
          }
        } else {
          this.$message.error('暂无操作权限！');
        }
      },
    },
  };
</script>

<style lang="scss" scoped>
  .el-card.is-always-shadow {
    border-radius: 10px;
  }
  .modul-title * {
    font-weight: bold;
    font-size: 18px;
    display: inline-block;
    vertical-align: middle;
  }
  .activity-wrap {
  }
  .activity-text {
    font-size: 12px;
    color: #a8a8ab;
  }
  .el-carousel__item {
    display: table-cell;
    text-align: center;
    vertical-align: middle;
  }

  .activity-status {
    display: inline-block;
    vertical-align: middle;
    background: #ff9a60;
    height: 19px;
    width: 50px;
    border-radius: 5px;
    padding: 5px;
    font-size: 12px;
    color: white;
    margin-right: 10px;
  }
  .box-card {
    margin-top: 10px;
  }
</style>
